//
//  HMUserAccount.swift
//  weibo
//
//  Created by LCH on 16/3/6.
//  Copyright © 2016年 lch. All rights reserved.
//

import UIKit

class HMUserAccount: NSObject,NSCoding {
    
    
    
    
    
    
      // 用户的id
    var uid: String?
    // 生命周期(秒数)
var expires_in: Double = 0 {

didSet {

 expires_date = NSDate().dateByAddingTimeInterval(expires_in)

}


}
    // 访问令牌
    var access_token: String?
    // 过期时间
    var remind_in: String?
    
    var screen_name: String?
    
    var avatar_large:String?
    
    var expires_date: NSDate?
    
    init(dict:[String:AnyObject]){
        
      super.init()
     
      setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    override var description:String {
    
      let keys = ["uid","expires_in","access_token"]
        
        return dictionaryWithValuesForKeys(keys).description
    
    
    }
    // 归档
    func encodeWithCoder(encoder: NSCoder) {
    
        encoder.encodeObject(uid,forKey: "uid")
        encoder.encodeObject(access_token,forKey: "access_token")
        encoder.encodeObject(remind_in, forKey: "remind_in")
        encoder.encodeObject(screen_name, forKey: "screen_name")
        encoder.encodeObject(avatar_large, forKey: "avatar_large")
        encoder.encodeDouble(expires_in, forKey: "expires_in")
        encoder.encodeObject(expires_date, forKey: "expires_date")
        
    }
    
    // 解档
    required init?(coder decoder: NSCoder) {
        uid = decoder.decodeObjectForKey("uid") as? String
        access_token = decoder.decodeObjectForKey("access_token") as? String
        remind_in = decoder.decodeObjectForKey("remind_in") as? String
        screen_name = decoder.decodeObjectForKey("screen_name") as? String
        avatar_large = decoder.decodeObjectForKey("avatar_large") as? String
        expires_in = decoder.decodeDoubleForKey("expires_in")
        expires_date = decoder.decodeObjectForKey("expires_date") as? NSDate
    }

    
    
    

}
